package sample;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;

public class Controller_tao<listView, WbView> {

    @FXML
    public Button mybutton;
    public static Message message=null;
    public static Stage st = null;
    // 与fxml_example.fxml文件中的登录提示框fx:id一致
        @FXML private Text actiontarget;
        @FXML private TextField mytext;
        @FXML private Pane pane;
    @FXML private TableColumn name;
    @FXML private TableColumn conNum;
    @FXML private TableColumn deathNum;
    @FXML private TableColumn cureNum;
    @FXML private TableColumn asymptomNum;
    @FXML private TableColumn updateTime;

    @FXML private TableView table;

        MessageDao dn = new MessageDao();

        // 为fxml_example.fxml文件中的登录按钮编写事件处理
        @FXML protected void handleSubmitButtonAction(ActionEvent event) {
            actiontarget.setText("点击了登录按钮");

    }
        @FXML protected void MyButton (ActionEvent event) throws SQLException, IOException {
            mybutton.setOnMouseClicked(new EventHandler<MouseEvent>() {
                @Override
                public void handle(MouseEvent event) {

                }
            });
            if (mytext.getText().trim().equals("") ) {
                // 显示对话框

                Alert alert = new Alert(Alert.AlertType.WARNING);
                alert.setHeaderText("输入为空查询失败！");
                alert.setContentText("请重新输入检索关键词");
                alert.show();
            }else if(dn.isExistCity(mytext.getText().trim())){
                Alert alert = new Alert(Alert.AlertType.WARNING);
                alert.setHeaderText("输入信息有误！");
                alert.setContentText("请重新输入！");
                alert.show();
            }
            else{

                String cityName="";
                cityName = mytext.getText().trim();
                 message=dn.getSqlConnection(cityName);
                URL url = new URL("file:src/sample/fxm3.fxml");

                try {
                    Scene scene = new Scene(FXMLLoader.load(url));
                    Stage stage1 = new Stage();
                    stage1.setScene(scene);
                    st = stage1;
                    stage1.show();

                } catch (IOException e) {
                    throw new RuntimeException(e);
                }


                    }
                };


            }





